<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

<!--统计给定字符串中字符出现的次数，并渲染到表格中-->

<table border="1px" >
	<tr>
		<th>字符</th>
		<th>出现次数</th>
	</tr>
</table>


<script>

    /**
     * 统计给定字符串中字符出现的次数
     * @param str：给定字符串
     */
    function countCharNum(str) {
        let obj = {};
        for (let i = 0; i < str.length; i++) {
            str[i] in obj ? obj[str[i]]++ : (obj[str[i]] = 1);
        }
        return obj;
    }

    const tbody = document.querySelector('tbody');
    const charObj = countCharNum(prompt('请输入一串字符'))
    for (let item in charObj) {
		tbody.innerHTML += `<tr><td>${item}</td><td>${charObj[item]}</td></tr>`;
    }

</script>

</body>
</html>